<?php
include('includes/connexion.php');
$elevemanager = new EleveManager($connexion);
session_start();
$accesmanager = new AccesManager($connexion);
$exercicemanager = new ExerciceManager($connexion);
$questionmanager = new QuestionManager($connexion);
$reponsemanager = new ReponseManager($connexion);
$interetspromanager = new InteretsProManager($connexion);

if(isset($_POST['idRefExercice']))
{
	foreach($_POST as $key => $value)
	{
		if($key != 'idRefExercice')
		{
			$newInteretsPro = new InteretsPro();
			$newInteretsPro->setIdRefReponse($key);
			$newInteretsPro->setIdRefEleve($_SESSION['Eleve']->id());
			$newInteretsPro->setClassement($value);
			$interetspromanager->add($newInteretsPro);
		}
	}
	if(isset($_GET['q'])){
		header('Location: go.php?ip&q');
	} else {
		header('Location: go.php?ip');
	}
}
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <title>Dashboard - Target Admin</title>

  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,400,600,700">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,300,700">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="js/libs/css/ui-lightness/jquery-ui-1.9.2.custom.min.css">
  <link rel="stylesheet" href="css/bootstrap.min.css">

  <!-- Plugin CSS -->
  <link rel="stylesheet" href="js/plugins/morris/morris.css">
  <link rel="stylesheet" href="js/plugins/icheck/skins/minimal/blue.css">
  <link rel="stylesheet" href="js/plugins/select2/select2.css">

  <!-- App CSS -->
  <link rel="stylesheet" href="css/target-admin.css">
  <link rel="stylesheet" href="css/custom.css">


  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->

</head>

<body>

<?php

include('includes/navbar.php');
include('includes/mainbar.php');
?>

<div class="container">

  <div class="content">

    <div class="content-container">
	<br><br>
      <div class="content-header">
        <h2 class="content-header-title">Intérêts professionnels</h2>
      </div> <!-- /.content-header --> 

      <div class="row">

        <div class="col-md-12">
			<form action="" method="post">
            	<?php
				foreach($questionmanager->getByExercice($_GET['id']) as $question)
				{
					echo $question->contenu()."<br>";
					?>
                    <table class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                                data-provide="datatable" 
                                data-length-change="true">
                        <thead>
                        <tr>
                            <th data-filterable="false">CHOIX</th>
                            <th data-filterable="false" data-sortable="true" data-direction="asc">CLASSEMENT</th>
                        </tr>
                        </thead>
                        <tbody>

                    <?php
					$max = $reponsemanager->getNbReponse($question->id());
					foreach($reponsemanager->getByQuestion($question->id()) as $reponse)
					{
						echo "<tr>";
						echo "<td>";
						if($reponse->contenu() === "NoText"){
						}else {		
							echo $reponse->contenu().' ';			
							}
			
						echo "</td>";					
						echo "<td>";
						echo "<input type='number' name='".$reponse->id()."' max='".$max."' min='1'/>";
						echo "</td>";
						echo "</tr>";
					}
				?>
                	</tbody>
                    </table>
                <?php
				}
				?>
                <input type="text" name="idRefExercice" value="<?php echo $_GET['id']; ?>" hidden/>
                <input type="submit" value="Envoyer" />
            </form>
        </div> <!-- /.col -->

      </div> <!-- /.row -->

    </div> <!-- /.content-container -->
      
  </div> <!-- /.content -->

</div> <!-- /.container -->


<?php include('includes/footer.php'); ?>

  <script src="js/libs/jquery-1.10.1.min.js"></script>
  <script src="js/libs/jquery-ui-1.9.2.custom.min.js"></script>
  <script src="js/libs/bootstrap.min.js"></script>

  <!--[if lt IE 9]>
  <script src="./js/libs/excanvas.compiled.js"></script>
  <![endif]-->

  <!-- App JS -->
  <script src="js/target-admin.js"></script>

</body>
</html>